package com.google;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class PurchaseDatabase
{
  private static final String DATABASE_NAME = "purchase.db";
  private static final int DATABASE_VERSION = 1;
  private static final String[] HISTORY_COLUMNS = { "_id", "productId", "state", "purchaseTime", "developerPayload" };
  public static final String HISTORY_DEVELOPER_PAYLOAD_COL = "developerPayload";
  public static final String HISTORY_ORDER_ID_COL = "_id";
  public static final String HISTORY_PRODUCT_ID_COL = "productId";
  public static final String HISTORY_PURCHASE_TIME_COL = "purchaseTime";
  public static final String HISTORY_STATE_COL = "state";
  private static final String[] PURCHASED_COLUMNS = { "_id", "quantity" };
  private static final String PURCHASED_ITEMS_TABLE_NAME = "purchased";
  public static final String PURCHASED_PRODUCT_ID_COL = "_id";
  public static final String PURCHASED_QUANTITY_COL = "quantity";
  private static final String PURCHASE_HISTORY_TABLE_NAME = "history";
  private static final String TAG = "PurchaseDatabase";
  private DatabaseHelper mDatabaseHelper;
  private SQLiteDatabase mDb;

  public PurchaseDatabase(Context paramContext)
  {
    this.mDatabaseHelper = new DatabaseHelper(paramContext);
    this.mDb = this.mDatabaseHelper.getWritableDatabase();
  }

  private void insertOrder(String paramString1, String paramString2, Consts.PurchaseState paramPurchaseState, long paramLong, String paramString3)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("_id", paramString1);
    localContentValues.put("productId", paramString2);
    localContentValues.put("state", Integer.valueOf(paramPurchaseState.ordinal()));
    localContentValues.put("purchaseTime", Long.valueOf(paramLong));
    localContentValues.put("developerPayload", paramString3);
    this.mDb.replace("history", null, localContentValues);
  }

  private void updatePurchasedItem(String paramString, int paramInt)
  {
    if (paramInt == 0)
    {
      this.mDb.delete("purchased", "_id=?", new String[] { paramString });
      return;
    }
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("_id", paramString);
    localContentValues.put("quantity", Integer.valueOf(paramInt));
    this.mDb.replace("purchased", null, localContentValues);
  }

  public void close()
  {
    this.mDatabaseHelper.close();
  }

  public Cursor queryAllPurchasedItems()
  {
    return this.mDb.query("purchased", PURCHASED_COLUMNS, null, null, null, null, null);
  }

  // ERROR //
  public int updatePurchase(String paramString1, String paramString2, Consts.PurchaseState paramPurchaseState, long paramLong, String paramString3)
  {
    // Byte code:
    //   0: aload_0
    //   1: monitorenter
    //   2: aload_0
    //   3: aload_1
    //   4: aload_2
    //   5: aload_3
    //   6: lload 4
    //   8: aload 6
    //   10: invokespecial 130	com/google/PurchaseDatabase:insertOrder	(Ljava/lang/String;Ljava/lang/String;Lcom/google/Consts$PurchaseState;JLjava/lang/String;)V
    //   13: aload_0
    //   14: getfield 71	com/google/PurchaseDatabase:mDb	Landroid/database/sqlite/SQLiteDatabase;
    //   17: ldc 39
    //   19: getstatic 52	com/google/PurchaseDatabase:HISTORY_COLUMNS	[Ljava/lang/String;
    //   22: ldc 132
    //   24: iconst_1
    //   25: anewarray 50	java/lang/String
    //   28: dup
    //   29: iconst_0
    //   30: aload_2
    //   31: aastore
    //   32: aconst_null
    //   33: aconst_null
    //   34: aconst_null
    //   35: aconst_null
    //   36: invokevirtual 135	android/database/sqlite/SQLiteDatabase:query	(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;
    //   39: astore 8
    //   41: aload 8
    //   43: ifnonnull +11 -> 54
    //   46: iconst_0
    //   47: istore 9
    //   49: aload_0
    //   50: monitorexit
    //   51: iload 9
    //   53: ireturn
    //   54: iconst_0
    //   55: istore 9
    //   57: aload 8
    //   59: invokeinterface 141 1 0
    //   64: ifeq +35 -> 99
    //   67: aload 8
    //   69: iconst_2
    //   70: invokeinterface 145 2 0
    //   75: invokestatic 148	com/google/Consts$PurchaseState:valueOf	(I)Lcom/google/Consts$PurchaseState;
    //   78: astore 11
    //   80: aload 11
    //   82: getstatic 152	com/google/Consts$PurchaseState:PURCHASED	Lcom/google/Consts$PurchaseState;
    //   85: if_acmpeq +60 -> 145
    //   88: aload 11
    //   90: getstatic 155	com/google/Consts$PurchaseState:REFUNDED	Lcom/google/Consts$PurchaseState;
    //   93: if_acmpne -36 -> 57
    //   96: goto +49 -> 145
    //   99: aload_0
    //   100: aload_2
    //   101: iload 9
    //   103: invokespecial 157	com/google/PurchaseDatabase:updatePurchasedItem	(Ljava/lang/String;I)V
    //   106: aload 8
    //   108: ifnull -59 -> 49
    //   111: aload 8
    //   113: invokeinterface 158 1 0
    //   118: goto -69 -> 49
    //   121: astore 7
    //   123: aload_0
    //   124: monitorexit
    //   125: aload 7
    //   127: athrow
    //   128: astore 10
    //   130: aload 8
    //   132: ifnull +10 -> 142
    //   135: aload 8
    //   137: invokeinterface 158 1 0
    //   142: aload 10
    //   144: athrow
    //   145: iinc 9 1
    //   148: goto -91 -> 57
    //
    // Exception table:
    //   from	to	target	type
    //   2	41	121	finally
    //   111	118	121	finally
    //   135	142	121	finally
    //   142	145	121	finally
    //   57	96	128	finally
    //   99	106	128	finally
  }

  private class DatabaseHelper extends SQLiteOpenHelper
  {
    public DatabaseHelper(Context arg2)
    {
      super("purchase.db", null, 1);
    }

    private void createPurchaseTable(SQLiteDatabase paramSQLiteDatabase)
    {
      paramSQLiteDatabase.execSQL("CREATE TABLE history(_id TEXT PRIMARY KEY, state INTEGER, productId TEXT, developerPayload TEXT, purchaseTime INTEGER)");
      paramSQLiteDatabase.execSQL("CREATE TABLE purchased(_id TEXT PRIMARY KEY, quantity INTEGER)");
    }

    public void onCreate(SQLiteDatabase paramSQLiteDatabase)
    {
      createPurchaseTable(paramSQLiteDatabase);
    }

    public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
    {
      if (paramInt2 != 1)
      {
        Log.w("PurchaseDatabase", "Database upgrade from old: " + paramInt1 + " to: " + paramInt2);
        paramSQLiteDatabase.execSQL("DROP TABLE IF EXISTS history");
        paramSQLiteDatabase.execSQL("DROP TABLE IF EXISTS purchased");
        createPurchaseTable(paramSQLiteDatabase);
      }
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.google.PurchaseDatabase
 * JD-Core Version:    0.6.2
 */